import time

from selenium.webdriver.common.by import By
from common.doLog import DoLog
from pages.basePage import BasePage

dolog = DoLog().set_get_logger()


class loginPage(BasePage):
    loginbutton1 = (By.XPATH, "//*[@id='ECS_MEMBERZONE']/a[1]")
    username = (By.NAME, "username")
    userpassword = (By.NAME, "password")
    loginbutton2 = (By.NAME, "submit")

    def login(self, username, password):
        # 已经在firstpage中实例化了
        # self.wd.get("http://192.168.110.134/")
        self.getElement(self.loginbutton1).click()
        # self.wd.find_element(*self.loginbutton1).click()
        # 输入账号
        self.getElement(self.username).send_keys(username)
        # self. wd.find_element(*self.username).send_keys(username)
        # 输入密码
        self.getElement(self.userpassword).send_keys(password)
        # self.wd.find_element(*self.userpassword).send_keys(password)
        # 点击立即登录按钮
        self.getElement(self.loginbutton2).click()
        # self.wd.find_element(*self.loginbutton2).click()
        time.sleep(3)

    def login_ok(self):
        time.sleep(2)
        return self.getElementValue(self.login_uname)

    def login_error_msg(self):
        return self.getElementValue(self.login_uname)

    def login_error_alert(self):
        return self.getAlertValue()

# if __name__ == '__main__':
# 通过实例打开断言
# l=loginPage().login(username="ljk", password="123456")
# l=loginPage().login(username="ljk", password="")
# l=loginPage().login(username="ljk", password="1456")
